require.sync('ShelvesEnum');
Ext.define('App.controller.goods.GoodsViewController', {
	extend : 'Ext.app.ViewController',
	alias : 'controller.goodsViewController',
	menu : Ext.widget('menu'),
	control : {
		'goodsView goodsList' : {
			beforerender : function(grid) {
				var buttons = {
					'bs/goods/saveGoods' : function(permit) {
						BaseUtil.createView('goods.GoodsWindow',permit,{storeId:'goods.GoodsStore'}).show();
					},
                    // 'bs/goods/saveListGoods' : function(permit) {Shelf Obtained
                    //     BaseUtil.createView('goods.GoodsListWindow',permit,{storeId:'goods.GoodsStore'}).show();
                    // }
				};
				BaseUtil.createPermitTbar(grid, buttons);
			},
			itemcontextmenu : function(view, record, item, index, e) {
				var id = record.get('id');
                var isShelves = record.get('isShelves'),store = Ext.StoreMgr.get('goods.GoodsStore');
				var menuitems=[];
				if(isShelves!=ShelvesEnum.YES.getValue()){
                    menuitems['bs/goods/updateGoods']=  function(permit) {
                        var win = BaseUtil.createView('goods.GoodsWindow',permit,{storeId:'goods.GoodsStore'});
                        win.down('form').loadRecord(record);
                        win.show();
                    }
                    menuitems['bs/goods/shelf']=  function(permit) {
                        BaseUtil.statusConfirm('确认上架些商品吗?',permit.url,id,store);
                    }
                }else{
                    menuitems['bs/goods/obtained']=  function(permit) {
                        BaseUtil.statusConfirm('确认下架此商品吗?',permit.url,id,store);
                    }
                }


				// var status = record.get('status'),store = Ext.StoreMgr.get('goods.GoodsStore');
				// if(status === StatusEnum.DELETE.getValue()){
				// 	menuitems['bs/goods/recover'] = function(permit) {
				// 		BaseUtil.statusConfirm('确认恢复此记录吗?',permit.url,id,store);
				// 	}
				// }else{
				// 	menuitems['bs/goods/removeGoods'] = function(permit) {
				// 		BaseUtil.statusConfirm('确认删除此记录吗?',permit.url,id,store);
				// 	}
				// }
				BaseUtil.createPermitMenu(view, this.menu, e, menuitems);
			},
			render : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('goods.GoodsStore'),Ext.getCmp('goodsView').down('goodsSearch form').getForm().getFieldValues());
			}
		},
		'goodsView goodsSearch [action=search] ' : {
			click : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('goods.GoodsStore'),Ext.getCmp('goodsView').down('goodsSearch form').getForm().getFieldValues());
			}
		}
	}
});